{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8d133756-c5a4-483b-a90c-34e49c5f3978",
   "metadata": {},
   "source": [
    "Chapter 8, 自定义函数\n",
    "# 构造模块、包\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a2236ae-d715-43b2-b6f4-3cb15ae9cc44",
   "metadata": {},
   "source": [
    "## 使用自定义模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2c5bda56-64f9-498b-982d-07126f4a6599",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "半径为 5 的圆的面积是 78.53981633974483\n",
      "半径为 5 的圆的周长是 31.41592653589793\n"
     ]
    }
   ],
   "source": [
    "import circle as cc\n",
    "\n",
    "r = 5\n",
    "area = cc.area(r)\n",
    "circumference = cc.circumference(r)\n",
    "\n",
    "print(\"半径为\", r, \"的圆的面积是\", area)\n",
    "print(\"半径为\", r, \"的圆的周长是\", circumference)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d673ffd-8dc7-42ac-928a-28d82e2c9624",
   "metadata": {},
   "source": [
    "## 使用自定义包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d05bbbc9-4ef0-4284-9d07-86ed9c253755",
   "metadata": {},
   "outputs": [],
   "source": [
    "from mylibrary.circle import area\n",
    "from mylibrary.linear_alg import inner_prod"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "710037b2-c222-4320-b0a2-096574a5c17f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "50.26548245743669"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = 4\n",
    "area(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "800b960b-ef60-408e-88c2-09c23f6a996b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "165"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 定义向量a和b\n",
    "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
    "b = a[::-1]\n",
    "\n",
    "# 调用函数\n",
    "inner_prod(a,b)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
